Important links for quick-sorting
	http://acatalept.com/blog/2008/10/28/stable-quicksort-in-javascript/
	
	<script>
		function quickSort(input) {
			if (input.length <= 1) return input;
			var pivot = Math.floor(Math.random()*input.length)
			var less = [], greater=[];
			var pivotElem = input.splice(pivot,1)
			document.writeln(pivotElem+'<br/>')
			for (x in input) {
				if (input[x] <= pivotElem[0])
					less.push(input[x])
				else
					greater.push(input[x])
			}
			document.writeln(less+'--'+greater+'<br/>')
			document.writeln('=============='+'<br/>')
			return [].concat(quickSort(less),pivotElem,quickSort(greater));
		}
		 
		
		document.writeln(quickSort([0,9,1,8,2,7,3,6,4,5]))
	</script>

====================================================================================

<SCRIPT LANGUAGE="JavaScript">
<!--
	var arr = [1,,,,,5];
	alert(arr.length);//6
//-->
</SCRIPT>

============================================================================


var fruits = ["Banana", "Orange", "Apple", "Mango"];
document.write(fruits.join() + "<br />"); // [Banana,Orange,Apple,Mango]
document.write(fruits.join("+") + "<br />");// [Banana+Orange+Apple+Mango]
document.write(fruits.join(" and ")); // [Banana and Orange and Apple and Mango]

==============================================================================================

var arr = [0,15,30,20,38];
document.write(Math.max.apply(null, arr));

=====================================================================================================
var parents = ["Jani", "Tove"];
var children = ["Cecilie", "Lone"];
var family = parents.concat(children);
document.write(family); // prints [Jani,Tove,Cecilie,Lone]

===========================================================================

var moreMixArray = new Array(7);
	alert(moreMixArray); /// prints like this     ,,,,,,,,
	alert(moreMixArray.length); // prints 7
===========================================================


var myArray = [ 'zero', 'one', 'two'];
var myArray = { 'zero', 'one', 'two'};// wrong way of declaring array

var x=[0,1,2,3,4,5];
var y=[x]; // here x is an array Object
document.writeln(y[0]); // Will output: 0,1,2,3,4,5
=======================================================

var myArray = [ 2, 5];
alert(myArray);
myArray[3] = 10; //remember no script error will be there
alert(myArray);
myArray[20] = null;
alert(myArray);
alert(myArray.length);


===========================================================

two-Dimensional Arrays
-----------------------
var x=[0,1,2,3,4,5];
var y=[x];
document.writeln(y[0][3]); // Will output: 2

==========================================================

Multi-Dimensional Arrays
---------------------------
document.writeln(bigArray[5][8][12][1])

=============================================================

JavaScript Associative Arrays
-------------------------------
An associative array is defined just like a regular array, but we insert some text in the place we had numbers in the regular arrays: 

var my_cars= new Array()
my_cars["cool"]="Mustang";
my_cars["family"]="Station Wagon";
my_cars["big"]="SUV";
my_cars[1]="SUV";
my_cars[2.0]="SUV";
my_cars[null]="SUV";

alert(my_cars.cool); //outputs Mustang
alert(my_cars.1); // script error
===============================================================

var my_cars= new Array()
my_cars["cool"]="Mustang";
my_cars["family"]="Station Wagon";
my_cars["big"]="SUV";
alert(my_cars);
alert(my_cars.length);  /// here the length will be 0 
my_cars[1]="SUV";
alert("After 1 : "+my_cars);
alert("After 1 length : "+my_cars.length);/// imm. after adding my_cars[1], length becomes 2
my_cars[2.5]="SUV";
my_cars[null]="SUV";
alert(my_cars);
alert(my_cars.length);
my_cars[3.0]="King";
alert("After 3 : "+my_cars);
alert("After 3 length : "+my_cars.length);


// if we want to know the array length, then my_cars[here numbers should be present not the strings or floting points like 1, 2.0 but not 2.5, "big"]

===============================================================

Mixed Arrarys
---------------

var mixArray = new Array();

mixArray[0] = "Hello World";
mixArray[1] = 100;

var anotherMixArray = new Array(200,
                                300,
                                "Hello Again",
                                500);

var moreMixArray = new Array();

moreMixArray[0] = 600;
moreMixArray[1] = mixArray;
moreMixArray[2] = new Array(700, anotherMixArray);
moreMixArray[3] = "Incredible!";

====================================================================

var myArray2= new Array();
myArray2[0] = "Football";
myArray2[1] = "Baseball";
myArray2[2] = "Cricket";
myArray2.sort();
alert(myArray2);// prints Baseball,Cricket,Football

======================================================================
var arr = new Array(5);
arr[0] = "Jani";
arr[1] = "Hege";
arr[2] = "Stale";
arr[3] = "Kai Jim";
arr[4] = "Borge";

document.write("Before : "+arr+"</br>");

// To add at the place of arr[2]
document.write("Answer  : "+arr.splice(2,0,"Lene")+"</br>"); //Answer  :
document.write("After  : "+arr+"</br>"); //After : Jani,Hege,Lene,Stale,Kai Jim,Borge

//to replace at the place of arr[2]
document.write("Answer  : "+arr.splice(2,1,"Lene")+"</br>"); //Answer : Stale  [this is replaced one] 							
document.write("After  : "+arr+"</br>"); //After : Jani,Hege,Lene,Kai Jim,Borge

//to delete at the place of arr[2]
document.write("Answer  : "+arr.splice(2,1)+"</br>");  //Answer : Stale  [this is removed one] 							
document.write("After  : "+arr+"</br>");//After : Jani,Hege,Kai Jim,Borge

==================================================================

// assumes a print function is defined
var myFish = ["angel", "clown", "mandarin", "surgeon"];
print("myFish: " + myFish);

var removed = myFish.splice(2, 0, "drum");
print("After adding 1: " + myFish);
print("removed is: " + removed);

removed = myFish.splice(3, 1);
print("After removing 1: " + myFish);
print("removed is: " + removed);

removed = myFish.splice(2, 1, "trumpet");
print("After replacing 1: " + myFish);
print("removed is: " + removed);

removed = myFish.splice(0, 2, "parrot", "anemone", "blue");
print("After replacing 2: " + myFish);
print("removed is: " + removed);


------

myFish: angel,clown,mandarin,surgeon
After adding 1: angel,clown,drum,mandarin,surgeon
removed is: 
After removing 1: angel,clown,drum,surgeon
removed is: mandarin
After replacing 1: angel,clown,trumpet,surgeon
removed is: drum
After replacing 2: parrot,anemone,blue,trumpet,surgeon
removed is: angel,clown

=======================================================

var myarray=["Bob", "Bully", "Amy"]
document.write("myarray : "+myarray+"</br>");
myarray.sort() ////Array now becomes ["Amy", "Bob", "Bully"]
myarray.reverse() //Array now becomes ["Bully", "Bob", "Amy"]
document.write("myarray : "+myarray+"</br>");

================================================================


var arr = new Array(3);
arr[0] = "Jani";
arr[1] = "Hege";
arr[2] = "Stale";

document.write(arr + "<br />"); //Jani,Hege,Stale
document.write(arr.pop() + "<br />");//Stale
document.write(arr);//Jani,Hege 




=========================================================================================



function distinctList(arrObj){
		
	var distinctArr = new Array;

	for(c in arrObj) {
		distinctArr[ arrObj[c] ] = c;
	}

	var i=-1;
	arrObj = new Array;
	for(c in distinctArr) {
		arrObj[++i] = c;
	}
	return arrObj;
}



==========Difference between push, pop, shift and unshift=========================================================================

/*

unshift does the same functionlity as push, but only difference is unshift inserts the element at 0 index place, where as push will insert after n place.
shift does the same functionlity as pop, but only difference is shift removes the element at 0 index place, where as push will removes at n place.

*/


var arr = ["nanda", "kumarg", "nkreddy"];
document.write(arr+' / arrLen : '+arr.length+'<br/>');
arr.push("nandaPush");
document.write("After pushing : "+arr+' / arrLen : '+arr.length+'<br/>');
var popped = arr.pop();
document.write("After poping : "+arr+' / arrLen : '+arr.length+'<br/>');
document.write("popped Arr : "+popped+' / poppedLen : '+popped.length+'<br/>');


arr.shift();
document.write("After shifting : "+arr+' / arrLen : '+arr.length+'<br/>');

arr.unshift("drum", "lion");
document.write("After unshifting : "+arr+' / arrLen : '+arr.length+'<br/>');


=================================================================================================================================


var sort_by = function(field, descOrder, primer) {
	descOrder = (descOrder) ? -1 : 1;
	return function(a, b) {
		a = a[field];
		b = b[field];
		if (typeof (primer) != 'undefined') {
			a = primer(a);
			b = primer(b);
		}
		if (a < b)
			return descOrder * -1;
		else if (a > b)
			return descOrder * 1;
		else
			return 0;
	}
}

// Sort by price high to low
homes.sort(sort_by('price', true, parseInt));

// Sort by city, case-insensitive, A-Z
homes.sort(sort_by('city', false, function(a) {
	return a.toUpperCase()
}));

var homes = [ {
	"h_id" : "3",
	"city" : "Dallas",
	"state" : "TX",
	"zip" : "75201",
	"price" : "162500"
}, {
	"h_id" : "4",
	"city" : "Bevery Hills",
	"state" : "CA",
	"zip" : "90210",
	"price" : "319250"
}, {
	"h_id" : "5",
	"city" : "New York",
	"state" : "NY",
	"zip" : "00010",
	"price" : "962500"
} ];

==================================================================================


Array.max = function( array ){
    return Math.max.apply( Math, array );
};
Array.min = function( array ){
    return Math.min.apply( Math, array );
};


